using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace RFCReader
{
    public partial class BookmarksForm : Form
    {
        public BookmarksForm(RFC rfc)
        {
            m_rfc = rfc;
            InitializeComponent();
            ShowBookmarks();
        }
        
        RFC m_rfc = null; 
        public void ShowBookmarks()
        {
            listBox1.Items.Clear();
            foreach (Bookmark b in m_rfc.bookmarks)
            {
                listBox1.Items.Add(string.Format("({0,-3}-{1,-3}) {2}", b.page, b.CurrentLine,m_rfc.GetPage(b.page).GetLine(b.CurrentLine).Trim()));
            }
        }
        Bookmark m_selectBookmark = null;
        public Bookmark GetSelectBookmark()
        {
            return m_selectBookmark;
        }
        private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                m_selectBookmark = m_rfc.bookmarks[listBox1.SelectedIndex];
                this.Close();
            }
        }

        private void listBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (listBox1.SelectedItem != null)
                {
                    m_selectBookmark = m_rfc.bookmarks[listBox1.SelectedIndex];
                    this.Close();
                }
            }
            else if (e.KeyCode == Keys.Escape)
            {
                m_selectBookmark = null;
                this.Close();
            }
            if (e.KeyCode == Keys.Delete)
            {
                if (listBox1.SelectedItem != null)
                {
                    m_rfc.bookmarks.RemoveAt(listBox1.SelectedIndex);
                    ShowBookmarks();
                }
            }
        }
        
    }
}